﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using DevMaker.SIC.Model;


namespace DevMaker.SIC.Dao {
    public class SucursalDao {
        public Sucursal Obtiene() {
            var sucursal = new Sucursal();
            var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SIC_Connection"].ToString());
            try {
                conn.Open();
                var command = new SqlCommand("SP_Sucursal_L", conn) { CommandType = CommandType.StoredProcedure };
                var reader = command.ExecuteReader();
                while (reader.Read()) {
                    sucursal.ReadFromDataReader(reader);
                }
            } catch (Exception ex) {
                Console.Write(ex.InnerException);
            } finally {
                conn.Close();
            }
            return sucursal;
        }
    }
}
